home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch01 / vdrmain.c < prev    next >
Text File  |  1994-03-20  |  6KB  |  212 lines

  1. /**
  2.  ** VDRMAIN.C ---- the public entry points of the VDR format graphics driver
  3.  **
  4.  ** Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5.  ** Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6.  ** Copyright (C) 1993 Grzegorz Mazur, gbm@ii.pw.edu.pl
  7.  **
  8.  ** This file is distributed under the terms listed in the document
  9.  ** "copying.dj", available from DJ Delorie at the address above.
  10.  ** A copy of "copying.dj" should accompany this file; if not, a copy
  11.  ** should be available from where this file was obtained.  This file
  12.  ** may not be distributed without a verbatim copy of "copying.dj".
  13.  **
  14.  ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  15.  ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16.  **/
  17.  
  18. #ifndef LARGEST_TEXT_WDT
  19. #define LARGEST_TEXT_WDT    132
  20. #define LARGEST_TEXT_HGT    60
  21. #endif
  22.  
  23. #ifndef LARGEST_NI_GRAPHICS_WDT
  24. #define LARGEST_NI_GRAPHICS_WDT 800
  25. #define LARGEST_NI_GRAPHICS_HGT 600
  26. #endif
  27.  
  28. #ifndef LARGEST_GRAPHICS_WDT
  29. #define LARGEST_GRAPHICS_WDT    1600
  30. #define LARGEST_GRAPHICS_HGT    1200
  31. #endif
  32.  
  33. #define SETUP_DS() do {                \
  34.     asm push  ds;                \
  35.     if(&driver_header == 0) {            \
  36.     /* do it only in drivers !! */        \
  37.     asm push  cs;                \
  38.     asm pop      ds;                \
  39.     }                        \
  40. } while(0)
  41.  
  42. #define RESET_DS() do {                \
  43.     asm pop   ds;                \
  44. } while(0);
  45.  
  46. char virtual_enabled = 0;
  47. int  virtual_xrange = 0;
  48. int  virtual_yrange = 0;
  49. int  current_start_row = 0;
  50. int  current_start_col = 0;
  51. int  virtual_wdt = 0;
  52. int  virtual_hgt = 0;
  53.  
  54. int far driver_init_routine(void)
  55. {
  56.     int result;
  57.  
  58.     SETUP_DS();
  59.     result = do_driver_init();
  60.     RESET_DS();
  61.     return(result);
  62. }
  63.  
  64. void far mode_set_routine(void)
  65. {
  66.     GrModeEntry *tbl,*mdp,*ok;
  67.     unsigned int mode = _AX;
  68.     unsigned int numc = _BX;
  69.     unsigned int wdt  = _CX;
  70.     unsigned int hgt  = _DX;
  71.     int flags,noclear;
  72.  
  73.     SETUP_DS();
  74.     noclear = mode & 0x80;
  75.     if((mode &= 0x7f) <= 3) {
  76.         tbl  = text_mode_table;
  77.         numc = 16;
  78.         switch(mode) {
  79.           case 0:        /* 80x25 text */
  80.         wdt = 80;
  81.         hgt = 25;
  82.         break;
  83.           case 1:        /* default text */
  84.         wdt = HDR->def_tw;
  85.         hgt = HDR->def_th;
  86.         break;
  87.           case 3:        /* largest text */
  88.         wdt = LARGEST_TEXT_WDT;
  89.         hgt = LARGEST_TEXT_HGT;
  90.         break;
  91.         }
  92.     }
  93.     else {
  94.         tbl = graphics_mode_table;
  95.         if(mode < 9) numc = HDR->def_numcolor;
  96.         switch(mode) {
  97.           case 4:        /* 320x200 graphics */
  98.         wdt = 320;
  99.         hgt = 200;
  100.         break;
  101.           case 5:        /* default graphics */
  102.         wdt = HDR->def_gw;
  103.         hgt = HDR->def_gh;
  104.         break;
  105.           case 7:        /* largest non-int graphics */
  106.         wdt = LARGEST_NI_GRAPHICS_WDT;
  107.         hgt = LARGEST_NI_GRAPHICS_HGT;
  108.         break;
  109.           case 8:        /* largest (possibly interlaced) graphics */
  110.         wdt = LARGEST_GRAPHICS_WDT;
  111.         hgt = LARGEST_GRAPHICS_HGT;
  112.         break;
  113.         }
  114.     }
  115.     for( ; ; ) {
  116.         /*
  117.          * find a suitable mode
  118.          */
  119.         for(mdp = tbl,ok = 0; mdp->width > 0; mdp++) {
  120.         if((ok) &&
  121.            (ok->number_of_colors >= numc) &&
  122.            (mdp->number_of_colors > ok->number_of_colors)) {
  123.             /* already found one w/ enough colors */
  124.             /* and this entry has more colors */
  125.             mdp = ok;
  126.             break;
  127.         }
  128.         if(mdp->mode.vdr.BIOS_mode != UNSUP) {
  129.             if((mdp->width >= wdt) &&
  130.                (mdp->height >= hgt) &&
  131.                (mdp->number_of_colors >= numc)) {
  132.                 /* found one big enough */
  133.                 break;
  134.             }
  135.             ok = mdp;
  136.         }
  137.         }
  138.         if(mdp->width == 0) {
  139.         mdp = ok;
  140.         if(!mdp) { flags = (-1); break; }
  141.         }
  142.         /*
  143.          * set up default parameters
  144.          * chip specific code can overwrite them if needed
  145.          */
  146.         HDR->line_offset = 0;            /* GRX figures it */
  147.         HDR->page_size_shift = 4;
  148.         HDR->page_gran_shift = 0;
  149.         HDR->wr_page_start = 0xa000;
  150.         HDR->rd_page_start = (HDR->driver_flags & GRD_RW_64K) ? 0xa000 : 0xffff;
  151.         HDR->r_mask = HDR->r_offs = 0;
  152.         HDR->g_mask = HDR->g_offs = 0;
  153.         HDR->b_mask = HDR->b_offs = 0;
  154.         HDR->f_mask = HDR->f_offs = 0;
  155.         /*
  156.          * initialize virtual parameters to their
  157.          * default values
  158.          */
  159.         virtual_enabled = 0;
  160.         virtual_wdt = wdt;
  161.         virtual_hgt = hgt;
  162.         if(mode == 10) {
  163.         if(HDR->virt_x_res > wdt) virtual_wdt = HDR->virt_x_res;
  164.         if(HDR->virt_y_res > hgt) virtual_hgt = HDR->virt_y_res;
  165.         }
  166.         flags = do_mode_set(mdp,noclear,
  167.         &virtual_wdt,&virtual_hgt,
  168.         &virtual_enabled
  169.         );
  170.         if(flags != (-1)) break;
  171.         /* invalidate this mode and try again ! */
  172.         mdp->mode.vdr.BIOS_mode = UNSUP;
  173.     }
  174.     wdt = mdp->width;
  175.     hgt = mdp->height;
  176.     if(virtual_enabled) {
  177.         virtual_xrange = virtual_wdt - wdt;
  178.         virtual_yrange = virtual_hgt - hgt;
  179.         if((signed int)(virtual_xrange | virtual_yrange) > 0) {
  180.         current_start_row = 0;
  181.         current_start_col = 0;
  182.         }
  183.         else virtual_enabled = 0;
  184.     }
  185.     HDR->virt_x_res = virtual_enabled ? virtual_wdt : wdt;
  186.     HDR->virt_y_res = virtual_enabled ? virtual_hgt : hgt;
  187.     _BX = flags;
  188.     _CX = wdt;
  189.     _DX = hgt;
  190.     RESET_DS();
  191. }
  192.  
  193. void far set_screen_start(void)
  194. {
  195.     int col = _CX;
  196.     int row = _DX;
  197.     SETUP_DS();
  198.     if(virtual_enabled) {
  199.         if(col < 0) col = 0;
  200.         if(row < 0) row = 0;
  201.         if(col > virtual_xrange) col = virtual_xrange;
  202.         if(row > virtual_yrange) row = virtual_yrange;
  203.         if((col != current_start_col) || (row != current_start_row)) {
  204.         current_start_col = col;
  205.         current_start_row = row;
  206.         do_screen_start_set(¤t_start_col,¤t_start_row);
  207.         }
  208.     }
  209.     RESET_DS();
  210. }
  211.  
  212.